using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace Trigits
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class StackContainer
    {
        public TriominoeContainer container;
        public Rectangle boundsShow;
        public Rectangle boundsHidden;
        private Rectangle boundsContainer;
        private SpriteFont font;

        private Texture2D backgroundShow;
        private Texture2D backgroundHidden;
        private int max;
        private GraphicsDeviceManager graphics;
        private bool hidden = false;

        public StackContainer(Rectangle boundsShow,Rectangle boundsHidden, Rectangle boundsContainer, Texture2D show, Texture2D hidden, int max, SpriteFont font, GraphicsDeviceManager graphics)
        {
            this.boundsShow = boundsShow;
            this.boundsHidden = boundsHidden;
            this.boundsContainer = boundsContainer;
            this.backgroundHidden = hidden;
            this.backgroundShow = show;
            this.max = max;
            this.font = font;
            this.graphics = graphics;

            container = new TriominoeStack(boundsContainer, max, font);
        }

        public void Update(GameTime gameTime, Triominoe inHand)
        {
            // TODO: Add your update code here
            container.update(gameTime, inHand);
            //base.Update(gameTime);
        }
        public void Draw(GraphicsDevice graphics, SpriteBatch spriteBatch, SpriteFont font, BasicEffect basicEffect)
        {

            if (hidden)
            {
                spriteBatch.Begin();
                basicEffect.CurrentTechnique.Passes[0].Apply();
                spriteBatch.Draw(backgroundHidden, boundsHidden, Color.White);
                spriteBatch.End();
            }
            else
            {
                spriteBatch.Begin();
                basicEffect.CurrentTechnique.Passes[0].Apply();
                spriteBatch.Draw(backgroundShow, boundsShow, Color.White);
                spriteBatch.End();
                //spriteBatch.Begin();
                //basicEffect.CurrentTechnique.Passes[0].Apply();
                container.draw(graphics, spriteBatch, font, basicEffect);
                //spriteBatch.End();
            }
        }


        public Boolean checkInContainer(Vector2 v)
        {
            if (v.X > boundsShow.X && v.X < (boundsShow.Width  + boundsShow.X) &&
                v.Y > boundsShow.Y && v.Y < (boundsShow.Height + boundsShow.Y))
                return true;
            return false;
        }
        public void showStack()
        {
            hidden = false;
        }
        public void hiddenStack()
        {
            hidden = true;
        }
        public bool isHidden()
        {
            return hidden;
        }
    }
}
